#include "kernel/types.h"
#include "kernel/stat.h"
#include "user/user.h"

int
main(int argc, char *argv[])
{
  int p1[2], p2[2];
  pipe(p1); pipe(p2);
  write(p1[1], "abc", 1);
  close(p1[1]);
  if(fork() == 0) {
    char buf[2];
    if(read(p1[0], buf, 1) == 1){
        printf("%d: received ping\n", getpid());
        close(p1[1]);
        write(p2[1], buf, 1);
        close(p2[0]); close(p2[1]);
        exit(0);
    }
    exit(1);
  }
  close(p2[1]);
  char buf[2];
  if(read(p2[0], buf, 1) == 1) {
    printf("%d: received pong\n", getpid());
    exit(0);
  }
  exit(1);

}
